#include "User.h"
#include "CryptoUtil.h"
#include <iostream>
#include <time.h>

//每写一个函数都要测试一下
using namespace std;
int main(){
    // srand(time(NULL));
    // string salt = CryptoUtil::generate_salt(10);
    // cout<<"salt = "<<salt<<endl;
    // string hashCode = CryptoUtil::hash_password("123456",salt);
    // cout<<"hashCode = "<<hashCode<<endl;//64个字符
    // User user = {1,"lihua","123456"};
    // string token = CryptoUtil::generate_token(user);
    // cout<<"token = "<<token<<endl;
    User user2;
    const char *token2 = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHBpcmUiOjE3NTUyMjU2ODUsImlkIjoxLCJzdWIiOiJsb2dpbiIsInVzZXJuYW1lIjoibGlodWEifQ.F53YYY1zFZOdWwETwdnxNvSvE6y4BKKaR1jC1oqhc-g";
    bool valid = CryptoUtil::verify_token(token2,user2);
    cout<<std::boolalpha<<"valid?"<<valid<<endl;
    if(valid){
        cout<<"User:id = "<<user2.id<<",username = "<<user2.username<<endl;
    }
    return 0;
}